$(function(){
	var pages;
	 ym.ajax({
        url: "/communication/quertCommunicationList",
        success: function (data) {
        	var data=JSON.parse(data);
          	if(data.res == 1){
          		var html = "";
          		pages = data.obj.pageNum;
	          	if(data.obj.results != null){
          			for(var i=0;i<data.obj.results.length;i++){
	          			var zhi = data.obj.results[i];
	          			html += '<li onclick="javascript:window.location.href=\'topic.html?exchangeId='+zhi.exchangeId+'&userid='+zhi.userId+'\'">';
	          			html += '<div class="topic">';
	          				html += '<img src="'+zhi.headimgurl+'">';
	          				html += '<div class="introduce">';
	          					html += '<h4>'+zhi.userName+'</h4>';
	          					html+="<span>"+zhi.createTimeString+"</span>"
	          					// html += '<span>123</span>';
	          				html += '</div>';
	          				html += '<div class="reply textright">';
	          					html += '<img src="../img/pinglun.png">';
	          					html += '<span>'+zhi.answersCount+'</span>';
	          				html += '</div>';
	          			html += '</div>';
	          			html += '<p>'+zhi.ecchangeMessage+'</p>';
	          			if(zhi.ymAttachments.length > 0){
	          				html += '<ul class="am-avg-sm-3 am-text-center kcyy1 font1 am-margin-top-sm" style="margin-left:3.8rem">';
	          				for(var j=0;j<zhi.ymAttachments.length;j++){
	          					if(zhi.ymAttachments.length > 1){
	          						html += '<li class="boderight"><img src="'+zhi.ymAttachments[j].attachmentUrl+'"></li>';
	          					}else{
	          						html += '<li><img src="'+zhi.ymAttachments[j].attachmentUrl+'"></li>';
	          					}
	          				}
	          			html += '</ul>';
	          			}
	          		}
          			$('.discusstopic').append(html);
          		}else{
      				html = '<li class="am-padding-top-sm am-text-center" style="margin-top:1rem"><img style="height:150px" src="../img/no.jpg"></li>';
					$('.discusstopic').append(html);
          		}
          		if(data.obj.totalRecord > 5){
					$('.more').removeClass('none');
				}
          	}
        }
    });
    /*点击查看更多*/
	$('body').on('click','.more',function(){
		pages = pages + 1;
		$("#my-modal-loading").modal('open');
		ym.ajax({
			url: "/communication/quertCommunicationList",
			param:{ 
				pageNum:pages,
			},
			success:function(data){
				setTimeout(function(){
					$("#my-modal-loading").modal('close');
				},300)
				var data=JSON.parse(data);
				if(data.res == 1){
	          		console.log(data);
	          		var html = "";
	          		pages = data.obj.pageNum;
	          		for(var i=0;i<data.obj.results.length;i++){
	          			var zhi = data.obj.results[i];
	          			html += '<li onclick="javascript:window.location.href=\'topic.html?exchangeId='+zhi.exchangeId+'&userid='+zhi.userId+'\'">';
	          			html += '<div class="topic">';
	          				html += '<img src="'+zhi.headimgurl+'">';
	          				html += '<div class="introduce">';
	          					html += '<h4>'+zhi.userName+'</h4>';
	          					// html += '<span>123</span>';
	          				html += '</div>';
	          				html += '<div class="reply textright">';
	          					html += '<img src="../img/pinglun.png">';
	          					html += '<span>'+zhi.answersCount+'</span>';
	          				html += '</div>';
	          			html += '</div>';
	          			html += '<p>'+zhi.ecchangeMessage+'</p>';
	          			if(zhi.ymAttachments.length > 0){
	          				html += '<ul class="am-avg-sm-3 am-text-center kcyy1 font1 am-margin-top-sm" style="margin-left:3.8rem">';
	          				for(var j=0;j<zhi.ymAttachments.length;j++){
	          					html += '<li><img src="'+zhi.ymAttachments[j].attachmentUrl+'"></li>';
	          				}
	          			html += '</ul>';
	          			}
	          		}
	          		if(data.obj.results.length < 5){
						$('.more').html('');
						$('.more').html('<p>到底啦</p>');
						$('.more').removeClass('more');
					}
	          		$('.discusstopic').append(html);
	          	}
			}
		});
	})
})